package com.example.bootdemo.listeners;

import com.example.bootdemo.service.impl.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;

public class ApplicationReadyListener implements ApplicationListener<ApplicationReadyEvent> {

    private static Logger logger = LoggerFactory.getLogger(ApplicationReadyListener.class);

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {

        logger.info("监听到ApplicationReadyEvent事件......");

        ConfigurableApplicationContext applicationContext = applicationReadyEvent.getApplicationContext();

        Object bean = applicationContext.getBean(UserServiceImpl.class);

        String className = bean.getClass().getName();

        logger.info("className={}",className);

    }
}
